Pearson Edexcel · GCSE · Computer Science

    Course version: 1CP2 · Version from Sept 2020

    Be able to write programs that use relational operators (equal to, less…

    Full specification wording

    Operators: 6.5.2 be able to write programs that use relational operators (equal to, less than, greater than, not equal to, less than or equal to, greater than or equal to)

    This criterion requires you to write program code that compares values using relational operators, which produce a Boolean result of true or false.

    Checked against the Pearson Edexcel 1CP2 specification (opens in a new tab) on .

    • Point 2 of 3
    • 4 key terms

    Study notes

    From the checked teaching notes for this specification point.

    The idea

    This criterion requires you to write program code that compares values using relational operators, which produce a Boolean result of true or false. In a language such as Python, equal to is written with two equals signs (score == 10), not equal to uses an exclamation mark before the equals sign (score != 10), less than and greater than use the angle brackets (score < 10 and score > 10), and the inclusive comparisons combine an angle bracket with an equals sign (score <= 10 and score >= 10). These results commonly control selection or iteration, for example if temperature >= 100: then sound an alarm, or while count < limit: to repeat a loop. Choose the operator that matches the boundary described, place the values in the correct order, and test with values just below, exactly on and just above the boundary.

    What earns the marks

    • Selects the relational operator that matches a stated comparison, for example greater than or equal to when a value on the boundary must also be accepted.
    • Writes a complete comparison with a value on each side of the operator, such as score >= 50 or name == "Ada".
    • Uses two equals signs for equality testing and reserves a single equals sign for assignment.
    • Uses the not-equal operator when a condition must be false for the tested value.
    • Places the operands in the correct order so the comparison means what is intended, for example age < 18 rather than 18 < age when testing for a minor.
    • Uses the Boolean result correctly in a selection or loop, for example as the condition of an if statement.

    Common mistakes and how to put them right

    • Using a single equals sign where a comparison is required.

      Put it right: A single equals sign assigns a value, so use two equals signs to test equality.

    • Reversing the operands so the comparison means the opposite of what is intended.

      Put it right: Read the comparison aloud in words and check that the subject and the limit are in the order described.

    • Treating less than as including the boundary value.

      Put it right: Less than excludes the boundary, so use less than or equal to when the boundary must be accepted.

    • Assuming a comparison returns a number rather than a Boolean.

      Put it right: Relational operators produce true or false, which is then used by the surrounding selection or loop.

    Exam tips

    • Underline the boundary words in the question, such as 'at least' or 'fewer than', because they decide whether the inclusive form is needed.
    • Test each candidate comparison with three values: one below the boundary, the boundary value itself and one above it.
    • Check the direction of the comparison by substituting a simple number and reading the result as a sentence.
    • Eliminate options that use a single equals sign for a comparison, since that is an assignment rather than a test.

    Try the lesson

    The start of the Operators: 6.5.2 be able to write programs that use relational operators (equal to, less than, greater than, not equal to, less than or equal to, greater than or equal to) lesson, made from checked teaching notes for this specification point.

    Have a go first

    A program contains the pseudocode IF score >= 50 THEN PRINT "Pass". The variable score holds the value 50. What is printed?

    Listen

    This criterion requires you to write program code that compares values using relational operators, which produce a Boolean result of true or false. In a language such as Python, equal to is written with two equals signs (score == 10), not equal to uses an exclamation mark before the equals sign (score != 10), less than and greater than use the angle brackets (score 10), and the inclusive comparisons combine an angle bracket with an equals sign (score = 10). These results commonly control selection or iteration, for example if temperature >= 100: then sound an alarm, or while count < limit: to repeat a loop. Choose the operator that matches the boundary described, place the values in the correct order, and test with values just below, exactly on and just above the boundary. A strong answer earns marks for these points. Selects the relational operator that matches a stated comparison, for example greater than or equal to when a value on the boundary must also be accepted. Writes a complete comparison with a value on each side of the operator, such as score >= 50 or name == "Ada". Uses two equals signs for equality testing and reserves a single equals sign for assignment. Uses the not-equal operator when a condition must be false for the tested value. A common slip: Using a single equals sign where a comparison is required. Instead, a single equals sign assigns a value, so use two equals signs to test equality. Exam tip: Underline the boundary words in the question, such as 'at least' or 'fewer than', because they decide whether the inclusive form is needed.

    See it

    A top-down flowchart. The top node is labelled 'Relational operators' and branches into six nodes: 'Equal to: ==', 'Not equal to: !=', 'Less than: <', 'Greater than: >', 'Less than or equal to: <=', and 'Greater than or equal to: >='. All six of these nodes lead into a single node labelled 'Boolean result: true or false', which then leads to a final node labelled 'Used in selection or iteration'.
    It classifies the six relational operators and shows that each produces a Boolean result used in selection or iteration.

    Key words

    Say what each word means before you turn the card.

    Relational operators

    Try answering aloud or in your head before turning the card.

    Equality testing versus assignment

    Try answering aloud or in your head before turning the card.

    Boolean result

    Try answering aloud or in your head before turning the card.

    Inclusive comparisons

    Try answering aloud or in your head before turning the card.

    See every definition
    Relational operators
    Operators that compare values and produce a Boolean result of true or false, including equal to, less than, greater than, not equal to, less than or equal to and greater than or equal to.
    Equality testing versus assignment
    Two equals signs test equality, while a single equals sign assigns a value.
    Boolean result
    The true or false produced by a comparison, commonly used to control selection or iteration.
    Inclusive comparisons
    Comparisons that combine an angle bracket with an equals sign, so the boundary value is also accepted.

    Label the diagram

    Some boxes have lost their names. Pick the right name for each number.

    The diagram again, with 3 boxes numbered instead of named. A top-down flowchart. The top node is labelled 'Relational operators' and branches into six nodes: 'Equal to: ==', 'Not equal to: !=', 'Less than: <', 'Greater than: >', 'Less than or equal to: <=', and 'Greater than or equal to: >='. All six of these nodes lead into a single node labelled 'Boolean result: true or false', which then leads to a final node labelled 'Used in selection or iteration'.
    • 1Box 1

    • 2Box 2

    • 3Box 3

    0 of 3 labelled

    There is more to this lesson

    The full lesson goes on to check your understanding and help you earn the marks. Create a free account to carry on, with your progress saved.

    Carry on with the full lesson

    A week of Premium from your first lesson · Then the free plan continues · No card, no charge

    Test your understanding of Operators: 6.5.2 be able to write programs that use relational operators (equal to, less than, greater than, not equal to, less than or equal to, greater than or equal to)

    Active recall beats re-reading. Take an instant quiz now to test what you’ve learned and lock it into long-term memory.

    Take topic quiz

    A week of Premium from your first lesson · Then the free plan continues · No card, no charge